﻿namespace KeRui.DAL
{
    using KeRui.DBUtility;
    using KeRui.Model;
    using System;
    using System.Data;
    using System.Data.SqlClient;

    public class CmsTemplateFileAttr
    {
        public int Add(KeRui.Model.CmsTemplateFileAttr model)
        {
            int num;
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@ID", SqlDbType.Int, 4), new SqlParameter("@FileID", SqlDbType.Int, 4), new SqlParameter("@PicPath", SqlDbType.NVarChar, 200), new SqlParameter("@HtmlPath", SqlDbType.NVarChar, 200), new SqlParameter("@Name", SqlDbType.NVarChar, 50), new SqlParameter("@Notes", SqlDbType.NVarChar, 50) };
            parameters[0].Direction = ParameterDirection.Output;
            parameters[1].Value = model.FileID;
            parameters[2].Value = model.PicPath;
            parameters[3].Value = model.HtmlPath;
            parameters[4].Value = model.Name;
            parameters[5].Value = model.Notes;
            DbHelperSQL.RunProcedure("CmsTemplateFileAttr_ADD", parameters, out num);
            return (int) parameters[0].Value;
        }

        public void Delete(int ID)
        {
            int num;
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@ID", SqlDbType.Int, 4) };
            parameters[0].Value = ID;
            DbHelperSQL.RunProcedure("CmsTemplateFileAttr_Delete", parameters, out num);
        }

        public bool Exists(int ID)
        {
            int num;
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@ID", SqlDbType.Int, 4) };
            parameters[0].Value = ID;
            return (DbHelperSQL.RunProcedure("CmsTemplateFileAttr_Exists", parameters, out num) == 1);
        }

        public KeRui.Model.CmsTemplateFileAttr GetModel(int ID)
        {
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@ID", SqlDbType.Int, 4) };
            parameters[0].Value = ID;
            KeRui.Model.CmsTemplateFileAttr attr = new KeRui.Model.CmsTemplateFileAttr();
            DataSet set = DbHelperSQL.RunProcedure("CmsTemplateFileAttr_GetModel", parameters, "ds");
            if (set.Tables[0].Rows.Count > 0)
            {
                if (set.Tables[0].Rows[0]["ID"].ToString() != "")
                {
                    attr.ID = int.Parse(set.Tables[0].Rows[0]["ID"].ToString());
                }
                if (set.Tables[0].Rows[0]["FileID"].ToString() != "")
                {
                    attr.FileID = int.Parse(set.Tables[0].Rows[0]["FileID"].ToString());
                }
                attr.PicPath = set.Tables[0].Rows[0]["PicPath"].ToString();
                attr.HtmlPath = set.Tables[0].Rows[0]["HtmlPath"].ToString();
                attr.Name = set.Tables[0].Rows[0]["Name"].ToString();
                attr.Notes = set.Tables[0].Rows[0]["Notes"].ToString();
                return attr;
            }
            return null;
        }

        public void Update(KeRui.Model.CmsTemplateFileAttr model)
        {
            int num;
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@ID", SqlDbType.Int, 4), new SqlParameter("@FileID", SqlDbType.Int, 4), new SqlParameter("@PicPath", SqlDbType.NVarChar, 200), new SqlParameter("@HtmlPath", SqlDbType.NVarChar, 200), new SqlParameter("@Name", SqlDbType.NVarChar, 50), new SqlParameter("@Notes", SqlDbType.NVarChar, 500) };
            parameters[0].Value = model.ID;
            parameters[1].Value = model.FileID;
            parameters[2].Value = model.PicPath;
            parameters[3].Value = model.HtmlPath;
            parameters[4].Value = model.Name;
            parameters[5].Value = model.Notes;
            DbHelperSQL.RunProcedure("CmsTemplateFileAttr_Update", parameters, out num);
        }
    }
}

